package us.icitap.cm.ui.shared;

import java.io.Serializable;
import java.util.List;

import us.icitap.cm.business.entities.PoliceCode;

import com.vaadin.data.util.HierarchicalContainer;

public class PoliceCodeContainer extends HierarchicalContainer implements Serializable{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7191799770001478759L;

	public PoliceCodeContainer(List<PoliceCode> rootPoliceCodeList) {
		
//		Result<List<PoliceCode>> result = CaseManagementUI.appStatelessBean.getPersistenceBean().getRootPoliceCode();
		
//			List<PoliceCode> list = result.getObject();
			for (PoliceCode policeCode : rootPoliceCodeList) {
				this.addItem(policeCode);
				rec(policeCode);
			}
		
		
	}
	public PoliceCodeContainer() {
		
	}
	
	private void rec(PoliceCode pc){
		for (PoliceCode polCo : pc.getChildrenPoliceCode()) {
			this.addItem(polCo);
			this.setParent(polCo, pc);
			this.rec(polCo);
		}
		
	}
	
	public void reload(List<PoliceCode> rootPoliceCodeList){
		removeAllItems();
		for (PoliceCode policeCode : rootPoliceCodeList) {
			this.addItem(policeCode);
			rec(policeCode);
		}
	}
}
